'use strict';
// 引入所有依赖库
var layer = require('layui-layer');
//////////////////////////////////////////////////////////////////////////////
// 信息提示
// 统一的文本弹窗layer控件
// =====================
// ##864297##flag
// =====================
// liuyp 2018年11月28日15: 30: 04
// 0叹号1对号2叉号3问号4锁5哭脸6笑脸7叹号重复
//////////////////////////////////////////////////////////////////////////////
function $alert() {
    var msg =  {
        loaded: false,
        msg: function (msg, option){
            layer.msg(msg, option)
        },
        alert: function (msg, option, cb){
            layer.alert(msg, option, function(index){
                if(cb){cb(function(){layer.close(index)})}
                else{layer.close(index)}
            });
        },
        success: function (msg, cb){
            if(cb){this.alert(msg||'提交成功！', {title: "成功",icon: 6}, cb)}
            else{this.msg(msg||'提交成功！', {icon: 6, time: 5e3, title: false})}
        },
        error: function (msg, cb){
            if(cb){this.alert(msg||'提交失败！', {title: "失败",icon: 5}, cb)}
            else{this.msg(msg||'提交失败！', {icon: 5, time: 5e3, title: false})}
        },
        warning: function (msg, cb){
            this.alert(msg||'警告提示！', {title: "警告",icon: 0}, cb)
        },
        info: function (msg, cb){
            this.alert(msg||'提示信息！', {title: "提示"}, cb)
        },
        confirm: function (msg, cb1, cb2, option){
            var op = {title: "请选择", icon: 3, btn: ['确定','取消']};
            if(option) angular.extend(op, option)
            layer.confirm(msg , op, function(index){
                if(cb1){cb1(function(){layer.close(index)})}
                else{layer.close(index)}
            }, function(index){
                if(cb2){cb2(function(){layer.close(index)})}
                else{layer.close(index)}
            });
        },
        prompt: function (title, cb, option){
            var op = {title: title||"请输入原因", formType: 2};
            if(option) angular.extend(op, option)
            layer.prompt(op, function(text, index){
                if(cb){cb(text,function(){layer.close(index)})}
                else{layer.close(index)}
            });
        },
        promptPw: function (title, cb){
            this.prompt(null, cb, {title: title||"确认口令", formType: 1})
        },
        open: function (option){
            layer.open(option)
        }
    }
    return msg
}
exports = module.exports = $alert;